package com.maikec.configure;
/**
 * 邢帅教育
 * <p>
 * 本源代码由数据中心及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2018. [图片]xsteach.com all rights reserved.
 */

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 跨域
 * @author maikec
 * @date 2018/7/23
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Value("${cors.mapping}")
    private String mapping;
    @Value("${cors.origins}")
    private String[] origins;
    @Value("${cors.maxAge}")
    private int maxAge;
    @Value("${cors.methods}")
    private String[] methods;
    @Value("${cors.headers}")
    private String [] headers;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping(mapping).allowedOrigins(origins)
                .maxAge(maxAge).allowedMethods(methods).exposedHeaders(headers);
    }
}
